<?php
include('../connect/connect_mysql.php');


function returnimages($page,$act) {
   $query = "Select * from image WHERE page_id = '$page' AND is_deleted = '0' ";
   if ($act == 'onpress'){
    	$query .= "ORDER BY `alies` DESC, `image_id` DESC";
   }
   $pattern="\.(jpg|jpeg|png|gif|bmp)$";
   mysql_query ("SET NAMES 'utf8'");
   $result = mysql_query($query);
   $data="";
   @$num_rows = mysql_num_rows($result);
    if($num_rows == 0) {
       return 0;
    } else {
        $curimage=0;
        while($row = mysql_fetch_array($result))
        {
            $file = $row['path'];
            $event_id = $row['event_id'];
			$width = $row['width'];
			$height = $row['height'];
            $description = $row['comment'];
			$thumb = $row['thumb'];
			$index = $row['alies'];
			$image_id = $row['image_id'];
			$data .= " [$curimage, \"$file\", \"$event_id\", \"$description\", \"$width\", \"$height\", \"$thumb\",\"$image_id\",\"$index\"],\n";
            $curimage++;
        }
		$data .= " [\"placeholder\"]\n";
    }
	return $data; 
}

	$act = $_POST['act'];
	if ($act == 'onpress'){
		$page = $_POST['page'];
		$str="";
		$str .= "{\n";
		$str .= "  baseurl: \"\",\n";
		$str .= "	images: [\n";
		if (returnimages($page,$act)){ 
	    	$str .= returnimages($page,$act);
		}
	    $str .= "	],\n";
	    $str .= "	desc: []\n";
	    $str .= "}\n";
		echo $str;
	}
	if ($act == 'content'){
		$page = $_POST['page'];
		$query = "SELECT * FROM `content` WHERE page_id = '$page' AND flag = '1' AND is_deleted = '0'";
		mysql_query ("SET NAMES 'utf8'");
   		$result = mysql_query($query);
   		@$num_rows = mysql_num_rows($result);
		if ($num_rows == 0){
			echo "";
		}else{
			while($row = mysql_fetch_array($result)){
				$content = $row['info'];
			}
			echo $content;
		}
	}
	if ($act == 'logo'){
		$page = $_POST['page'];
		$query = "SELECT * FROM `logo` WHERE page_id = '$page' AND flag = '1' AND is_deleted = '0'";
		mysql_query ("SET NAMES 'utf8'");
   		$result = mysql_query($query);
   		@$num_rows = mysql_num_rows($result);
		if ($num_rows == 0){
			echo "";
		}else{
		 	$curimage=0;
			$data="";
			while($row = mysql_fetch_array($result)){
				$location = $row['location']; 
				$path = $row['path'];
				$data .= " [$curimage, \"$location\", \"$path\"],\n";
	            $curimage++;
			}
			$data .= " [\"placeholder\"]\n";
			$str = "{\nimages :[".$data."]}\n" ;
			echo $str;
		}
	}
?>
